/**
 * 
 */
package cn.agiledata.bank.common.util;

import java.util.Random;
import java.util.Vector;

import cn.agiledata.bank.account.service.ISequenceGenerator;
import cn.agiledata.bank.common.service.CommonService;
import com.vnv.infrastructure.logic.IPBAppFactory;

/**
 * @author 马贤波
 *
 * Apr 5, 2006
 */
public class UniqueIdentityUtil {
	
	private static Random random = new Random() ;
	
	private static ISequenceGenerator getSeqService() {
		return (ISequenceGenerator) IPBAppFactory.getObj(ISequenceGenerator.SERVICE_NAME) ;
	}
	
	private static CommonService getCommonService() {
		return (CommonService) IPBAppFactory.getObj(CommonService.SERVICE_NAME) ;
	}
	
	/** 主账户ID获得（暂时） */
	synchronized public static String getAccountId (String registerPerson,String registerMethod ) {
		String result = getSeqService().getAccountSequence(registerPerson,registerMethod) ;
		return result ;
	}
	
	/** 子账户ID获得（暂时） */
	public static String getSubAccountId (String accountId) {
		String result = String.valueOf(System.currentTimeMillis()) ;
		return result ;
	}

	public static String getTransactionSequence ()  {
		return getSeqService().getTransactionSequence() ;
	}

	public static String getTransactionSequence (String userType, String txType)  {
		return getSeqService().getTransactionSequence() ;
	}
	
	public static String getBarCodePayFeeNo ()  {
		return getSeqService().getBarCodeOrderId() ;
	}
	
	public static String getMobileChargeRecordNo ()  {
		return getSeqService().getMobileChargeRecordNo() ;
	}
	
	public static String getUpadjustApplyNo ()  {
		return getSeqService().getUpauditApplyId();
	}
	
	public static String getPayPaperSequence () {
		return getSeqService().getPayPaperSequence();
	}
	
	public static String getReceivePaperSequence () {
		return getSeqService().getReceivePaperSequence();
	}
	
	public static String getTransferPaperSequence () {
		return getSeqService().getTransferPaperSequence();
	}
	
	public static String getRemitVerifyCode () {
		return getCommonService().retrieveAlphaRandomCode(8, "[A-Z]",true) ;
	}
	
	public static String getUserActiveCode () {
		return getCommonService().retrieveAlphaRandomCode(15, "[A-Za-z0-9]") ;
	}
	
	public static String createLoginPass () {
		return getCommonService().retrieveAlphaRandomCode(8, "[A-Za-z0-9]") ;
	}
	
	public static String createPayPass () {
		return getCommonService().retrieveAlphaRandomCode(12, "[A-Za-z0-9]") ;
	}
	
	public static String createRandomString (int digit) {
		
		String result = "" ;
		
		for (int i = 0; i < digit; i++){
		    String rand=String.valueOf(random.nextInt(10));
		    result += rand;
		}
		
		return result ;
	}
	
	public static String createRandomStringAndNumber(int digit) {
		String result = "" ;
		Vector vector = new Vector();
		for(int upper=65;upper <= 90;upper++) { //大写
			vector.add(String.valueOf((char)upper));
		}
		for(int lower=97;lower <= 122;lower++) { //小写
			vector.add(String.valueOf((char)lower));
		}
		for (int i = 0; i < digit; i++){
			 if(random.nextBoolean()) { //数字
				 String rand=String.valueOf(random.nextInt(10));
				 result += rand;
			 } else { //字符
				 String rand=(String)vector.elementAt(random.nextInt(52));
				 result += rand;
			 }
			
		}
		return result ;
	}
    
    public static String getTransactionBatchNoSequence(){
        return getSeqService().getTransactionBatchNo();
    }
	
	public static void main(String[] args) {
		for (int i = 0 ; i < 100 ; i ++) {
//			String str = getUserActiveCode() ;

		}
		
	}

}
